package com.venutech.gongan.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.venutech.gongan.dao.WorkSpConfigMapper;
import com.venutech.gongan.entity.WorkSpConfig;
import com.venutech.gongan.model.ResultFormat;
import com.venutech.gongan.service.WorkSpConfigService;
import com.venutech.gongan.util.ResultUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

//import com.venutech.imd.dao.WorkSpConfigMapper

@Service
public class WorkSpConfigServiceImpl implements WorkSpConfigService {
    @Resource
    private WorkSpConfigMapper workSpConfigMapper;

    @Override
    public ResultFormat insert(WorkSpConfig workSpConfig) {
        Integer insert = workSpConfigMapper.insert(workSpConfig);
        if (insert > 0) {
            return ResultUtil.success();
        }else {
            return ResultUtil.error(100,"用户添加失败");
        }
    }

    @Override
    public int delete(int wkcfg_id) {
        return workSpConfigMapper.delete(wkcfg_id);
    }

    @Override
    public Page<WorkSpConfig> getInfo(Integer pageNo, Integer pageSize) {
        Page<WorkSpConfig> page = new Page<>(pageNo,pageSize);
        List<WorkSpConfig> list  =  workSpConfigMapper.getList(page);
        return page.setRecords(list);
    }

    @Override
    public int updateWorkSpConfig(WorkSpConfig workSpConfig) {
        return workSpConfigMapper.updateWorkSpConfig(workSpConfig);
    }

    @Override
    public WorkSpConfig getById(Integer wkcfg_id) {
        return workSpConfigMapper.getById(wkcfg_id);
    }

    @Override
    public WorkSpConfig getFirstSpUser(Integer workType) {
        List<WorkSpConfig> spConfigs = workSpConfigMapper.findByWorkType(workType);
        if(CollectionUtils.isEmpty(spConfigs)) {
            return null;
        }
        return spConfigs.get(0);
    }

    @Override
    public List<WorkSpConfig> getByWorkType(Integer workType) {
        return workSpConfigMapper.findByWorkType(workType);
    }

}
